import { Input } from "antd"
import { FC } from "react"

import { SFormItem } from "@/components/common"
import { useLocale } from "@/locales"
import { validateUser } from "@/utils/validate"

export type AgentNameInputField = {
	agentNameInputCode: string
}
const AgentNameInput: FC<any> = props => {
	const { formatMessage } = useLocale()
	const { required, validator, placeholder } = props

	return (
		<SFormItem
			name="userName"
			label={formatMessage({ id: "common.agent_number" })}
			rules={[
				{
					required: required,
					validator: validator
						? (_: any, value: any) => validateUser(formatMessage, value)
						: (_: any, value: any) => Promise.resolve(value)
				}
			]}
		>
			<Input allowClear style={{ width: "200px" }} placeholder={formatMessage({ id: placeholder })} />
		</SFormItem>
	)
}

export default AgentNameInput
